﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Serialization;
using System.Data.Objects.DataClasses;

namespace Common.Serializable
{
    public class EFContractResolver : DefaultContractResolver
    {
        protected override IList<JsonProperty> CreateProperties(JsonObjectContract contract)
        {
            IList<JsonProperty> properties = base.CreateProperties(contract);

            for (int i =0;i<properties.Count;i++)
            {
                if (properties[i].PropertyName == "EntityKey"
                    || properties[i].PropertyName == "EntityState")
                {
                    properties.RemoveAt(i--);
                    continue;
                }
                //在 partial entity的属性被忽略，具体原因未知，暂时作如下处理
                //if (properties[i].Ignored)
                //    properties[i].Ignored = false;

               
            }
            return properties;
        }

    }
}
